<template>
  <div id="box">
    <!-- <img src="../assets//images//bg.jpg" alt="" style="max-width: 100%;max-height: 100%;"> -->
    <div id="login">
      <div id="l-box">
        <h2>供应链</h2>
        <p style="margin: 0;">
          <i class="el-icon-user-solid"></i>
          <!-- <input placeholder="账号" type="text" v-model="loginUser.loginName"> -->
          <el-input v-model="loginUser.loginName" placeholder="账号"></el-input>

        </p>
        <p>
          <i class="el-icon-lock"></i>
          <!-- <input placeholder="密码" type="password" v-model="loginUser.password"> -->
          <el-input v-model="loginUser.password" type="password" placeholder="密码" show-password></el-input>
        </p>
        <p>
          <el-select style="width: 160px;" v-model="loginUser.userRole" placeholder="请选择公司">
            <el-option :value="1" label="公司1"></el-option>
            <el-option :value="0" label="公司2"></el-option>
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </p>
        <p>
          <el-row>
            <el-button id="login-btn" v-loading="showFlag" type="primary" @click="doLogin">登录</el-button>
          </el-row>
        </p>
        <router-link style="color: #c77869;position: relative;left: 150px;top: 20px;" to="register">点我注册</router-link>
      </div>

    </div>

  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginUser: {
        loginName: '',
        password: '',
        userRole: '',
      },
      showClose: false,
      showFlag: false
    }
  },
  methods: {
    doLogin() {
      this.axios.post('/api/login/doLogin',
        this.loginUser
      ).then(rs => {
        if (rs.data.code == 200) {
          sessionStorage.setItem("token", rs.data.map.token)
          this.showFlag = true
          setTimeout(() => {
            this.loginSuccess()
            this.showFlag = false
            this.$router.replace('/firstIndex')
          }, 1000)
        } else {
          this.$message({
            // showClose: true,
            message: rs.data.msg,
            type: 'error',
            center: true,
            duration: 1000
          });
        }
      })

    },
    loginSuccess() {
      this.$message({
        // showClose: true,
        message: '登录成功',
        type: 'success',
        center: true,
        duration: 1000
      });
    },

  },
}
</script>

<style scoped>
#box {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background-image: url(../../assets/image/bg.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}


#l-box {
  width: 100%;
  height: 280px;
  background-color: white;
}

.el-input {
  margin-left: 10px;
}

#login {
  width: 480px;
  margin: auto;
  position: relative;
  top: 70px;
  text-align: center;
  border-radius: 30px;
  overflow: hidden;

}

.el-input {
  width: 240px;
  margin-bottom: 10px;
}

#login input {
  width: 240px;
  height: 34px;
  font-size: 16px;
  padding-left: 10px;
  border: 1px solid #a5a6a7;
  /* border: none;
  border-bottom: 1px solid gray; */
  margin-left: 10px;
  outline: none;
}

/* .el-input--suffix .el-input__inner {
  position: relative;
  left: 50px;
} */

#l-box h2 {
  margin: 0;
  padding: 0;
  position: relative;
  top: -70px;
  color: #c77869;
}

#l-box {
  padding-top: 100px;
}

#login-btn {
  background-color: #c77869;
  border: none;
  width: 180px;
  margin-top: 30px;
  height: 40px;
}
</style>